import { Ref, ref } from 'vue';

export function useScrollToError(
  parent: Ref<Element | Document> = ref(document),
  selector = '.ant-input-affix-wrapper-status-error',
) {
  function scrollIntoView() {
    const el = parent.value.querySelector(selector);
    if (el) {
      el.scrollIntoView({
        behavior: 'smooth',
        block: 'start',
      });
    }
  }

  return { scrollIntoView };
}
